<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    function show() {
      let pro = new Promise((resolve, reject) => {
        setTimeout(() => {
          // resolve("成功")
          reject("失败")
        }, 2000);
      })

      return pro;

    }

    // catch 相当于then的第二个为失败的回调函数
    show().then(data => {
      console.log(data);
    }).catch(error => {
      console.log(error);
    })
  </script>
</body>

</html>